using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Management;
using System.Text;
using System.Windows.Forms;

namespace csharpsysinfo
{
    public partial class DevicesForm : Form
    {
        public DevicesForm()
        {
            InitializeComponent();
        }

        private string GetSoundCardInfo()
        {
            string soundCardInfoString;
            int soundCardCounterInteger;

            soundCardCounterInteger = 1;

            soundCardInfoString = "Failed to retrieve info.";


            ManagementObjectSearcher managementobjectsearcher = new ManagementObjectSearcher
            ("SELECT * FROM  Win32_SoundDevice");

            ManagementObjectCollection managementobjectcollection = managementobjectsearcher.Get();

            foreach (ManagementObject mob in managementobjectcollection)
            {
                try
                {
                    if (soundCardCounterInteger == 1)
                    {
                        soundCardInfoString = mob.Properties["Name"].Value.ToString();
                        soundCardDevicesTextBox.Text = soundCardInfoString;
                    }
                }
                catch
                {
                }

                try
                {
                    if (soundCardCounterInteger == 2)
                    {
                        soundCardInfoString = mob.Properties["Name"].Value.ToString();
                        soundCardDevices2TextBox.Text = soundCardInfoString;
                    }
                }
                catch
                {
                }


                soundCardCounterInteger++;
            }

            return soundCardInfoString;
        }


        private void DevicesForm_Load(object sender, EventArgs e)
        {
            GetSoundCardInfo();
        }
    }
}